<?php
/**
 * ACTION_URL_MODEL:admin.php?c=admin/user/actionName-method&p1=v1&p2=v2
 * admin.php?c=admin-user-actionName--method---p1-v1--p2-v2--p3-v3
 * @return unknown_type
 */
function loadAction()
{
	global $_DUDULOOK;
	$_DUDULOOK['c'] = trim($_GET['c']);
	if($_DUDULOOK['c']) $actionData = explode("-", $_DUDULOOK['c']);
	$_DUDULOOK['action']['name'] = 'IndexAction';
	$_DUDULOOK['action']['method'] = 'index';
	
	$path = "";
	if($actionData)
	{
		$actionArr = explode("/", $actionData[0]);
		$_DUDULOOK['action']['name'] = array_pop($actionArr) . 'Action';
		$path = implode("/",$actionArr);
		if($actionData[1]) $_DUDULOOK['action']['method'] = $actionData[1]; //method
	}
	
	$actionPath = (PROJECT_PACKAGE ? PROJECT_PACKAGE . '/' : '')  .  'action/' . ($path ? $path . '/' : '');
	$_DUDULOOK['action']['fullPath'] = $actionPath;
	$path = implode(".", explode("/", $_DUDULOOK['action']['fullPath'])) . $_DUDULOOK['action']['name'];
	
	define("ACTION_NAME", $_DUDULOOK['action']['name']);
	define('ACTION_METHOD', $_DUDULOOK['action']['method']);
	$pageContext = ClassFactory::forName('com.dudulook.base.BasePageContext');
	$obj = ClassFactory::forName($path, $pageContext);
	if(!method_exists($obj, $_DUDULOOK['action']['method'])) throw new Exception('method ' . ACTION_NAME . '::' . $_DUDULOOK['action']['method'] . '() not exist');
	
	pageLoad($pageContext);
	
	$obj->$_DUDULOOK['action']['method']();
}

function pageLoad($pageContext)
{
	$configerFactory = ClassFactory::forName('com.dudulook.base.factory.ConfigerFactory');
	$configer = $configerFactory->create();
	try
	{
		$res = $configer->get('config.web:pageLoad');
		if($res)
		{
			foreach($res as $item)
			{
				ClassFactory::forName($item, $pageContext);
			}
		}
	}
	catch(Exception $e)
	{
		throw new Exception('pageLoad error : ' . $e->getMessage());
	}
	
}

function url($action, $params = array(), $file = '')
{
	return ActionRouterFactory::create()->url($action, $params, $file);
}

function getWebUrl()
{
	$url = "http://" . $_SERVER['HTTP_HOST'];

	return $url;
}
?>